﻿using personalplaner.business.enums;
using System.Windows.Media;
using personalplaner.business.extensions;

namespace personalplaner.business.stamm
{
	public class PlanSchemaItem : ItemBase
	{
		public override int ID
		{
			get
			{
				return _schemaID;
			}
			set
			{
				_schemaID = value;
				RaisePropertyChanged("SchemaID");
				RaisePropertyChanged("ID");
			}
		}

		int _schemaID;
		public int SchemaID
		{
			get { return _schemaID; }
			set
			{
				_schemaID = value;
				RaisePropertyChanged("SchemaID");
			}
		}

		int _personSchemaID;
		public int PersonSchemaID
		{
			get { return _personSchemaID; }
			set
			{
				_personSchemaID = value;
				RaisePropertyChanged("PersonSchemaID");
			}
		}

		enPlanRowType _rowType;
		public enPlanRowType RowType
		{
			get { return _rowType; }
			set
			{
				_rowType = value;
				RaisePropertyChanged("RowType");

				switch (value)
				{
					case enPlanRowType.None:
						_prsID = -1;
						break;
					case enPlanRowType.Abteilung:
						_prsID = 0;
						break;
					case enPlanRowType.Person:
						//CWA: is this correct????
                        if (_prsID <= 0)
                            _prsID = 1000;
						break;
				}

				RaisePropertyChanged("PrsID");
			}
		}

		int _prsID;
		public int PrsID
		{
			get { return _prsID; }
			set
			{
				_prsID = value;
				RaisePropertyChanged("PrsID");

				switch (value)
				{
					case -1:
						_rowType = enPlanRowType.None;
						break;
					case 0:
						_rowType = enPlanRowType.Abteilung;
						break;
					default:
						_rowType = enPlanRowType.Person;
						break;
				}
				RaisePropertyChanged("RowType");
			}
		}

		string _vorname;
		public string Vorname
		{
			get { return _vorname; }
			set
			{
				_vorname = value;
				RaisePropertyChanged("Vorname");
			}
		}

		string _nachname;
		public string Nachname
		{
			get { return _nachname; }
			set
			{
				_nachname = value;
				RaisePropertyChanged("Nachname");
			}
		}

		int _abteilungID;
		public int AbteilungID
		{
			get { return _abteilungID; }
			set
			{
				_abteilungID = value;
				RaisePropertyChanged("AbteilungID");
			}
		}

		string _abteilungName;
		public string AbteilungName
		{
			get { return _abteilungName; }
			set
			{
				_abteilungName = value;
				RaisePropertyChanged("AbteilungName");
			}
		}

		public int RGB
		{
			get
			{
				return Color.ToInt();
			}
			set
			{
				if (Color == null)
					Color = value.ToColor();
			}
		}

		Color? _color;
		public Color? Color
		{
			get { return _color; }
			set
			{
				_color = value;
				RaisePropertyChanged("Color");
			}
		}

		public string ColorString
		{
			get
			{
				return Color.ToArgbString();
			}
			set
			{
				if (Color == null)
					Color = value.ToColor();
			}
		}

        bool _showPrsId;
        public bool ShowPrsId
        {
            get
            {
                return _showPrsId;
            }
            set
            {
                _showPrsId = value;
                RaisePropertyChanged("ShowPrsId");
            }
        }

        enNameDisplay _nameDisplay = enNameDisplay.NameVorname;
        public enNameDisplay NameDisplay
        {
            get
            {
                return _nameDisplay;
            }
            set
            {
                _nameDisplay = value;
            }
        }

        public string DisplayName
        {
            get
            {
                var str = string.Format("{0} {1}", Nachname, Vorname);
                switch (NameDisplay)
                {
                    case enNameDisplay.VornameName:
                        str = string.Format("{0} {1}", Vorname, Nachname);
                        break;
                    case enNameDisplay.NameVorname:
                        str = string.Format("{0} {1}", Nachname, Vorname);
                        break;
                    case enNameDisplay.NameV:
                        str = string.Format("{0} {1}.", Nachname, !string.IsNullOrEmpty(Vorname) ? Vorname.Substring(0, 1) : "");
                        break;
                    case enNameDisplay.Name:
                        str = Nachname;
                        break;
                }
                return str;
            }
        }
	}
}
